package czk.concrent.threadpool.newFixedThreadPool.practice;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicIntegerArray;

/**
 * 线程池的线程重命名
 * @Author:ChenZhangKun
 * @Date: 2020/8/24 23:30
 */
public class ThreadPoolRename {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(2, new ThreadFactory() {
            // 定义原子变量
            AtomicInteger atomicInteger = new AtomicInteger(1);

            @Override
            public Thread newThread(Runnable r) {
                return new Thread(r, "myThread_" + atomicInteger.getAndIncrement());
            }
        });
        executorService.execute(()->{
            System.out.println(Thread.currentThread().getName()+"  今天");
        });
        executorService.execute(()->{
            System.out.println(Thread.currentThread().getName()+"  我");
        });
        executorService.execute(()->{
            System.out.println(Thread.currentThread().getName()+"  爱你");
        });
    }
}
